///////////////////////////////////////////////////////////////
// Copyright(c) BeingStudio
// 
// FileName : public
// Creator  : ChenShiCai
// E-Mail   : BeingStudio@GMail.com
// Date     : 2008-05-31
// Comment  : 
//
///////////////////////////////////////////////////////////////
#ifndef _PUBLIC_
#define _PUBLIC_

#include <assert.h>

#ifndef ASSERT
#define ASSERT assert
#endif

#define PROCESS_ERROR(Condition) \
    do  \
    {   \
    if (!(Condition))   \
    goto Exit0;     \
    } while (false)


#define PROCESS_SUCCESS(Condition) \
    do  \
    {   \
    if (Condition)      \
    goto Exit1;     \
    } while (false)



#define PROCESS_ERROR_RET_CODE(Condition, Code) \
    do  \
    {   \
    if (!(Condition))       \
        {                       \
        nResult = Code;     \
        goto Exit0;         \
        }                       \
    } while (false)

#define PROCESS_ERROR_RET_COM_CODE(Condition, Code) \
    do  \
    {   \
    if (!(Condition))       \
        {                       \
        hrResult = Code;     \
        goto Exit0;         \
        }                       \
    } while (false)


#define COM_PROCESS_ERROR(Condition) \
    do  \
    {   \
    if (FAILED(Condition))  \
    goto Exit0;         \
    } while (false)


#define COM_PROCESS_SUCCESS(Condition)   \
    do  \
    {   \
    if (SUCCEEDED(Condition))   \
    goto Exit1;             \
    } while (false)


#define COM_PROC_ERROR_RET_CODE(Condition, Code)     \
    do  \
    {   \
    if (FAILED(Condition))  \
        {                       \
        hrResult = Code;    \
        goto Exit0;         \
        }                       \
    } while (false)


#define COM_RELEASE(pInterface) \
    do  \
    {   \
    if (pInterface)                 \
        {                               \
        (pInterface)->Release();    \
        (pInterface) = NULL;        \
        }                               \
    } while (false)


#define SAFE_DELETE_ARRAY(pArray)     \
    do  \
    {   \
    if (pArray)                 \
        {                           \
        delete [](pArray);      \
        (pArray) = NULL;        \
        }                           \
    } while (false)


#define SAFE_DELETE(p)    \
    do  \
    {   \
    if (p)              \
        {                   \
        delete (p);     \
        (p) = NULL;     \
        }                   \
    } while (false)

#define CHECK_ERROR(Condition) \
    do  \
    {   \
    if (!(Condition))       \
        {                       \
        }                       \
    } while (false)


#define COM_CHECK_ERROR(Condition) \
    do  \
    {   \
    if (FAILED(Condition))       \
        {                       \
        }                       \
    } while (false)

#ifdef _DEBUG

#define ASSERT_EXIT(Condition) \
    do  \
    {   \
    assert(Condition);  \
    if (!(Condition))   \
    goto Exit0;     \
    } while (false)

#else

#define ASSERT_EXIT(Condition)  \
    do  \
    {   \
    if (!(Condition))       \
    goto Exit0;         \
    } while (false)


#endif

#endif//_PUBLIC_


